﻿using System;
using System.Runtime.InteropServices;

namespace WirelessAccessPoint.InteropServices
{
    public static class Wlanapi
    {
        /// <summary>
        /// The WlanFreeMemory function frees memory. Any memory returned from
        /// Native Wifi functions must be freed.
        /// </summary>
        [DllImport("Wlanapi.dll")]
        public static extern void WlanFreeMemory(IntPtr pMemory);

        /// <summary>
        /// The WlanOpenHandle function opens a connection to the server.
        /// </summary>
        [DllImport("Wlanapi.dll")]
        public static extern uint WlanOpenHandle(
            uint dwClientVersion,
            IntPtr pReserved,
            out uint pdwNegotiatedVersion,
            ref IntPtr phClientHandle);

        /// <summary>
        /// The WlanCloseHandle function closes a connection to the server.
        /// </summary>
        [DllImport("Wlanapi.dll")]
        public static extern uint WlanCloseHandle(
            IntPtr hClientHandle,
            IntPtr pReserved);

        /// <summary>
        /// The WlanHostedNetworkInitSettings function configures and persists
        /// to storage the network connection settings (SSID and maximum number
        /// of peers, for example) on the wireless Hosted Network if these
        /// settings are not already configured.
        /// </summary>
        [DllImport("Wlanapi.dll")]
        public static extern uint WlanHostedNetworkInitSettings(
            IntPtr hClientHandle,
            out WLAN_HOSTED_NETWORK_REASON pFailReason,
            IntPtr pReserved);

        /// <summary>
        /// The WlanHostedNetworkQueryStatus function queries the current
        /// status of the wireless Hosted Network.
        /// </summary>
        [DllImport("Wlanapi.dll")]
        public static extern uint WlanHostedNetworkQueryStatus(
            IntPtr hClientHandle,
            out IntPtr ppWlanHostedNetworkStatus,
            IntPtr pReserved);

        /// <summary>
        /// The WlanHostedNetworkForceStart function transitions the wireless
        /// Hosted Network to the wlan_hosted_network_active state without
        /// associating the request with the application's calling handle.
        /// </summary>
        [DllImport("Wlanapi.dll")]
        public static extern uint WlanHostedNetworkForceStart(
            IntPtr hClientHandle,
            out WLAN_HOSTED_NETWORK_REASON pFailReason,
            IntPtr pReserved);

        /// <summary>
        /// The WlanHostedNetworkForceStop function transitions the wireless
        /// Hosted Network to the wlan_hosted_network_idle without associating
        /// the request with the application's calling handle.
        /// </summary>
        [DllImport("Wlanapi.dll")]
        public static extern uint WlanHostedNetworkForceStop(
            IntPtr hClientHandle,
            out WLAN_HOSTED_NETWORK_REASON pFailReason,
            IntPtr pReserved);

        /// <summary>
        /// The WlanHostedNetworkQueryProperty function queries the current
        /// static properties of the wireless Hosted Network.
        /// </summary>
        [DllImport("Wlanapi.dll")]
        public static extern uint WlanHostedNetworkQueryProperty(
            IntPtr hClientHandle,
            WLAN_HOSTED_NETWORK_OPCODE OpCode,
            out uint pdwDataSize,
            out IntPtr ppvData,
            out WLAN_OPCODE_VALUE_TYPE pWlanOpcodeValueType,
            IntPtr pReserved);

        /// <summary>
        /// The WlanHostedNetworkSetProperty function sets static properties of
        /// the wireless Hosted Network.
        /// </summary>
        [DllImport("Wlanapi.dll")]
        public static extern uint WlanHostedNetworkSetProperty(
            IntPtr hClientHandle,
            WLAN_HOSTED_NETWORK_OPCODE OpCode,
            uint dwDataSize,
            IntPtr pvData,
            out WLAN_HOSTED_NETWORK_REASON pFailReason,
            IntPtr pReserved);

        /// <summary>
        /// The WlanHostedNetworkQuerySecondaryKey function queries the
        /// secondary security key that is configured to be used by the
        /// wireless Hosted Network.
        /// </summary>
        [DllImport("Wlanapi.dll")]
        public static extern uint WlanHostedNetworkQuerySecondaryKey(
            IntPtr hClientHandle,
            out uint pdwKeyLength,
            out IntPtr ppucKeyData,
            out bool pbIsPassPhrase,
            out bool pbPersistent,
            out WLAN_HOSTED_NETWORK_REASON pFailReason,
            IntPtr pReserved);

        /// <summary>
        /// The WlanHostedNetworkSetSecondaryKey function configures the
        /// secondary security key that will be used by the wireless Hosted
        /// Network.
        /// </summary>
        [DllImport("Wlanapi.dll")]
        public static extern uint WlanHostedNetworkSetSecondaryKey(
            IntPtr hClientHandle,
            uint dwKeyLength,
            [MarshalAs(UnmanagedType.LPStr)] string pucKeyData,
            bool bIsPassPhrase,
            bool bPersistent,
            out WLAN_HOSTED_NETWORK_REASON pFailReason,
            IntPtr pReserved);

        /// <summary>
        /// The WlanRegisterNotification function is used to register and
        /// unregister notifications on all wireless interfaces.
        /// </summary>
        [DllImport("Wlanapi.dll")]
        public static extern uint WlanRegisterNotification(
            IntPtr hClientHandle,
            WLAN_NOTIFICATION_SOURCE dwNotifSource,
            bool bIgnoreDuplicate,
            WLAN_NOTIFICATION_CALLBACK funcCallback,
            IntPtr pCallbackContext,
            IntPtr pReserved,
            out WLAN_NOTIFICATION_SOURCE pdwPrevNotifSource);
    }
}
